package com.epcs.subGNuevosNegocios.eci.struts.exceptionHandler;

import java.net.URL;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ExceptionHandler;
import org.apache.struts.config.ExceptionConfig;
import org.omg.CORBA.CTX_RESTRICT_SCOPE;

import weblogic.common.T3ServicesDef;

public class LoginExceptionHandler extends ExceptionHandler {
	private static 	 
	Logger logger =
        Logger.getLogger(LoginExceptionHandler.class);
	
	@Override
	public ActionForward execute(Exception ex, ExceptionConfig ae,
			ActionMapping mapping, ActionForm formInstance,
			HttpServletRequest request, HttpServletResponse response)
			throws ServletException {

		Throwable cause = ex.getCause();
		String message = ex.getMessage();
		
		logger.error(message,ex);
		request.setAttribute("error", message);
		
		return super.execute(ex, ae, mapping, formInstance, request, response);
	}

	public LoginExceptionHandler() {
		// TODO Auto-generated constructor stub

		 String resource =
	         "eci-web_log4j.properties";

		 	 
		 URL configFileResource =
			 LoginExceptionHandler.class.getResource(resource);
		 
		 PropertyConfigurator.configure(configFileResource);	
	}

}
